package com.example.administrator.mobilesafe.utils;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

/**
 * Created by Administrator on 2015/8/28.
 */
public abstract class BaseSetupAcitivity extends Activity {
    protected SharedPreferences sharedPreferences;
    private GestureDetector gestureDetector;
    protected void onCreate(Bundle saveInstanceState){
        super.onCreate(saveInstanceState);
        gestureDetector = new GestureDetector(this,new GestureDetector.SimpleOnGestureListener(){
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                if(Math.abs(velocityX)< 200){
                    Toast.makeText(getBaseContext(), "滑动有些慢哥们", Toast.LENGTH_SHORT).show();
                    return true;
                }
                if(Math.abs((e2.getRawY() - e1.getRawY())) >200){
                    Toast.makeText(getBaseContext(), "不能这样滑动", Toast.LENGTH_SHORT).show();
                    return true;
                }
                if(e2.getRawX() - e1.getRawX()>200){
                    showPre();
                    return true;
                }else if (e1.getRawX() - e2.getRawX()>200){
                    showNext();
                    return true;
                }
                return super.onFling(e1, e2, velocityX, velocityY);
            }
        });

    }
    public boolean onTouchEvent(MotionEvent motionEvent){
        gestureDetector.onTouchEvent(motionEvent);
        return super.onTouchEvent(motionEvent);
    }
    public void next(View view){
        showNext();
    }
    public void pre(View view){
        showPre();
    }
    public abstract void showPre() ;
    public abstract void showNext() ;
}
